<?php
include 'common/autoload.php';
include 'common/header.html';
include 'common/left.html';

$w = " AND " . $_SESSION['memberID'];
$flag = false;
$post_url = 'prod_edits.html?type=f';
// $post_url = 'prod_edits_dt.php?type=f';
$str = "SELECT id, title,p_type,getPY(title,1) as py FROM uu_land "
    ."WHERE apply_did={$_SESSION['memberID']} AND status=1 ORDER BY py ASC";
$GLOBALS['le']->query($str);
$prods = array();
while($row=$GLOBALS['le']->fetch_assoc()) {
    $prods['1'][] = $row;
}

// 可分销产品
$sale = new \pft\Prod\Sale($GLOBALS['le'], $_SESSION['memberID']);
$pid_arr = $sale->GetProdsid();

if(count($pid_arr)){
	$sql_apply_did = "SELECT p.id,p.apply_did,l.title,l.id as lid FROM uu_products p LEFT JOIN uu_jq_ticket t ON p.id=t.pid LEFT JOIN uu_land l ON t.landid=l.id WHERE p.id IN(".implode(',',$pid_arr).") AND p.apply_limit=1 AND p.p_status IN(0,2,3,4,5)";
	$GLOBALS['le']->query($sql_apply_did);
	$fxIds = array();
	while($list = $GLOBALS['le']->fetch_assoc()){
		$fxIds[] = $list['lid'];
	}
	if(count($fxIds)){
		$str = "SELECT id, title,p_type,getPY(title,1) as py FROM uu_land "
			."WHERE status=1 AND id IN (".implode(',',$fxIds).") ORDER BY py ASC";
		$GLOBALS['le']->query($str);
		while($row=$GLOBALS['le']->fetch_assoc()) {
			$prods['1'][] = $row;
		}
	}
}

$tmp = array();
$sortType='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
for($i=0;$i<strlen($sortType);$i++){
	foreach($prods[1] as $k=>$val){
		if($sortType[$i]==$val['py']){
			$tmp[]=$val;
			unset($prods[1][$k]);
		}
	}
}
$prods[1]=$tmp;
?>
<link rel="stylesheet" href="css/aliceui.min.css">
<link rel="stylesheet" href="css/resetui.css">
<link rel="stylesheet" href="css/prod_package.css?v=1010">
<link rel="stylesheet" href="css/prod_package_f.css?v=1010">
<style>

.input-wrap{ position: relative; height: 45px; line-height: 38px; margin-bottom: 10px; background: url('./images/img/searchtext.gif') no-repeat left top; }
.input-wrap input{ width: 326px; padding: 0 5px; height: 32px; line-height: 32px; border: 0 none; background: none; margin: 7px 0 0 7px; color: #666; line-height: 30px\9; _line-height: 32px; vertical-align: -10px\9; _vertical-align: -9px; font-size: 14px; font-weight: bold; position: absolute; top: 0; left: 110px;}
.input-wrap span{font-weight: bold;color:#020202; font-size:16px; text-align:center;margin-left:16px; }
</style>
<div class="wrap">
    <div class="left"> 
	<div class="input-wrap">
					 <input type="text" class="searchtext" name="user_filter" id="user_filter">
					<span class="qcha">快速查找:</span>
			 	</div>
	
        <div id="prod_result" class="list">
            <?foreach($prods as $key=>$prod){?>
            <ul id="prod_r<?=$key?>" class="prod_list">
                <?foreach($prod as $p){?>
                    <li class="<?=$p['p_type']?>">
                        <label>
                            <input type="checkbox" class="chkbox" data-title="<?=$p['title']?>" value="<?=$p['id']?>" name="p1[]"><?=$p['py']?>-<?=$p['title']?>
                        </label>
                    </li>
                <?}?>
            </ul>
            <?}?>
        </div>
		
		
		
		
		
		
		
		
		
		
		
		
		
        <div id="tickt_result"></div>
        <div class="btn">
		   
            <button type="button" class="ui-button ui-button-lorange" id="submit">下一步</button>
        </div>
    </div>
    <div class="right">
        <h2>您选择的产品</h2>
        <ul class="selected" id="selected"></ul>
    </div>
</div> 
<script type="text/javascript">
(function(){
	$("ul.tabHead").on('click', 'li', function(){
		var wrap = $(this).attr('data-wrap'),c='buyers';
		$(this).addClass('current')
			.siblings('li.current')
			.removeClass('current');
		if($("#buyers_user_"+wrap).length) {
			$("#buyers_user_"+wrap).show().siblings('ul').hide();
		}
	});
	$(".list").on('click','input:radio', function(){
		html = $(this).attr("data-name")+"["+$(this).siblings().html()+"]";
		$("#applyer").text(html).removeClass('nochoice');
		$("input[name='apply_did']").val($(this).val());
		if($("button#sub").hasClass('ui-button-sdisable')){
			$("button#sub").removeClass('ui-button-sdisable')
				.addClass('ui-button-sorange')
				.removeAttr('disabled');
		}
		$(".pmid").val($(this).val());
		
	});
	$("input#user_filter").on('keyup',function(){
		var user_list = $("div.list:visible").find('li'),
			len = user_list.length,
			i= 0,
			searchTxt = $(this).val();
		if(searchTxt=='') {
			return;
		}
		if(!isNaN(searchTxt) && searchTxt.length<6) {
			return;
		}
		for(;i<len;i++) {
			if(user_list[i].innerText.indexOf(searchTxt)>-1) {
				//console.log(user_list[i].innerText);
				$(user_list[i]).css('background-color','#ffff66');
				var a = $(user_list[i]).parents('ul.user_list').attr('data-alpha');
				$("ul.tabHead").find("li[data-wrap='"+a+"'").trigger("click");
//                $("li[data-wrap='"+a+"'").trigger('click');
			} else {
				$(user_list[i]).css('background-color','#fff');
			}
		}
	});
	 
})();

</script>
<form id="hideFrm" action="<?=$post_url;?>" method="post">
    <input type="hidden" name="package_data"/>
</form>
<script src="js/json2.js"></script>
<script src='js/prod_package.js'></script>
<?include('common/footer.html');?>